package sun.springboot.mqtt_integration.core.messageSend;

import org.springframework.integration.mqtt.outbound.MqttPahoMessageHandler;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.stereotype.Component;

/**
 * 消息发送实现
 */
@Component
public class MqttSendImpl implements MqttSend {

    private MqttPahoMessageHandler mqttOutbound;

    public MqttSendImpl(MqttPahoMessageHandler mqttOutbound) {
        this.mqttOutbound = mqttOutbound;
    }


    @Override
    public void mqttSend(MqttSendObject mqttSendObject) {
        mqttOutbound.setDefaultTopic(mqttSendObject.getTopic());
        mqttOutbound.setDefaultQos(mqttSendObject.getQos());
        mqttOutbound.handleMessage(new GenericMessage(mqttSendObject.getData()));
    }
}
